<?php

use Illuminate\Database\Seeder;
use SmallRuralDog\Admin\Auth\Database\Menu;

class MenuTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $menu_list = json_decode(self::getMenuJsonData(), 1);

        if (!empty($menu_list['data']))
        {
            DB::statement('SET FOREIGN_KEY_CHECKS=0;');
            Menu::truncate();
            DB::statement('SET FOREIGN_KEY_CHECKS=1;');

            foreach ($menu_list['data'] as $key=>$val)
            {
                $menu = new Menu;
                $menu->id = $val['id'];
                $menu->parent_id = $val['parent_id'];
                $menu->order = $val['order'];
                $menu->title = $val['title'];
                $menu->icon = $val['icon'];
                $menu->uri = $val['uri'];
                $menu->permission = $val['permission'];
                $menu->save();
            }
        }
    }

    public static function getMenuJsonData()
    {
        return '{
            "data":
            [
                {
                    "id": 1,
                    "parent_id": 0,
                    "order": 1,
                    "title": "首页",
                    "icon": "el-icon-monitor",
                    "uri": "home",
                    "permission": "[2]",
                    "created_at": "2020-06-02 00:27:42",
                    "updated_at": "2020-06-23 22:03:22"
                },
                {
                    "id": 2,
                    "parent_id": 0,
                    "order": 2,
                    "title": "系统",
                    "icon": "el-icon-setting",
                    "uri": "system",
                    "permission": null,
                    "created_at": "2020-06-02 00:27:42",
                    "updated_at": "2020-06-02 00:27:42"
                },
                {
                    "id": 3,
                    "parent_id": 2,
                    "order": 3,
                    "title": "管理员",
                    "icon": "el-icon-s-custom",
                    "uri": "auth/users",
                    "permission": null,
                    "created_at": "2020-06-02 00:27:42",
                    "updated_at": "2020-06-04 22:36:50"
                },
                {
                    "id": 4,
                    "parent_id": 2,
                    "order": 4,
                    "title": "角色",
                    "icon": "el-icon-s-open",
                    "uri": "auth/roles",
                    "permission": null,
                    "created_at": "2020-06-02 00:27:42",
                    "updated_at": "2020-06-04 22:37:47"
                },
                {
                    "id": 5,
                    "parent_id": 2,
                    "order": 5,
                    "title": "权限",
                    "icon": "el-icon-s-release",
                    "uri": "auth/permissions",
                    "permission": null,
                    "created_at": "2020-06-02 00:27:42",
                    "updated_at": "2020-06-04 22:38:08"
                },
                {
                    "id": 6,
                    "parent_id": 2,
                    "order": 6,
                    "title": "菜单",
                    "icon": "el-icon-finished",
                    "uri": "auth/menu",
                    "permission": null,
                    "created_at": "2020-06-02 00:27:42",
                    "updated_at": "2020-06-04 22:38:34"
                },
                {
                    "id": 7,
                    "parent_id": 2,
                    "order": 7,
                    "title": "操作日志",
                    "icon": "el-icon-tickets",
                    "uri": "auth/logs",
                    "permission": null,
                    "created_at": "2020-06-02 00:27:42",
                    "updated_at": "2020-06-04 22:39:18"
                },
                {
                    "id": 11,
                    "parent_id": 0,
                    "order": 4,
                    "title": "商品",
                    "icon": "el-icon-goods",
                    "uri": "goods",
                    "permission": "[9,10,11]",
                    "created_at": "2020-06-02 18:46:52",
                    "updated_at": "2020-06-23 22:11:51"
                },
                {
                    "id": 13,
                    "parent_id": 11,
                    "order": 3,
                    "title": "分类管理",
                    "icon": "el-icon-ice-cream-round",
                    "uri": "goods/class",
                    "permission": "[11]",
                    "created_at": "2020-06-02 23:27:47",
                    "updated_at": "2020-06-23 22:11:31"
                },
                {
                    "id": 14,
                    "parent_id": 11,
                    "order": 1,
                    "title": "品牌管理",
                    "icon": "el-icon-ice-cream-square",
                    "uri": "goods/brand",
                    "permission": "[9]",
                    "created_at": "2020-06-02 23:45:24",
                    "updated_at": "2020-06-23 22:11:04"
                },
                {
                    "id": 15,
                    "parent_id": 11,
                    "order": 1,
                    "title": "产品管理",
                    "icon": "el-icon-orange",
                    "uri": "goods/list",
                    "permission": "[10]",
                    "created_at": "2020-06-03 16:02:17",
                    "updated_at": "2020-06-23 22:11:17"
                },
                {
                    "id": 16,
                    "parent_id": 0,
                    "order": 6,
                    "title": "活动",
                    "icon": "el-icon-cherry",
                    "uri": "activity",
                    "permission": "[14,15]",
                    "created_at": "2020-06-03 17:50:50",
                    "updated_at": "2020-06-23 22:18:58"
                },
                {
                    "id": 17,
                    "parent_id": 16,
                    "order": 1,
                    "title": "活动管理",
                    "icon": "el-icon-cherry",
                    "uri": "activity/list",
                    "permission": "[14]",
                    "created_at": "2020-06-03 17:51:34",
                    "updated_at": "2020-06-23 22:19:08"
                },
                {
                    "id": 18,
                    "parent_id": 0,
                    "order": 7,
                    "title": "社区",
                    "icon": "el-icon-mobile-phone",
                    "uri": "community",
                    "permission": "[16]",
                    "created_at": "2020-06-03 17:53:33",
                    "updated_at": "2020-06-23 22:19:28"
                },
                {
                    "id": 19,
                    "parent_id": 18,
                    "order": 1,
                    "title": "社区管理",
                    "icon": "el-icon-refrigerator",
                    "uri": "community",
                    "permission": "[16]",
                    "created_at": "2020-06-03 17:53:52",
                    "updated_at": "2020-06-23 22:19:37"
                },
                {
                    "id": 21,
                    "parent_id": 0,
                    "order": 8,
                    "title": "设置",
                    "icon": "el-icon-setting",
                    "uri": "setting",
                    "permission": "[17,18]",
                    "created_at": "2020-06-04 22:53:47",
                    "updated_at": "2020-06-23 22:06:16"
                },
                {
                    "id": 22,
                    "parent_id": 21,
                    "order": 1,
                    "title": "基本设置",
                    "icon": "el-icon-office-building",
                    "uri": "setting",
                    "permission": "[17]",
                    "created_at": "2020-06-04 22:55:31",
                    "updated_at": "2020-06-23 22:06:44"
                },
                {
                    "id": 23,
                    "parent_id": 0,
                    "order": 5,
                    "title": "订单",
                    "icon": "el-icon-shopping-cart-full",
                    "uri": "orders",
                    "permission": "[1]",
                    "created_at": "2020-06-05 15:30:10",
                    "updated_at": "2020-06-23 22:05:23"
                },
                {
                    "id": 24,
                    "parent_id": 23,
                    "order": 1,
                    "title": "订单管理",
                    "icon": "el-icon-shopping-cart-1",
                    "uri": "orders",
                    "permission": "[12]",
                    "created_at": "2020-06-05 15:31:33",
                    "updated_at": "2020-06-23 22:10:10"
                },
                {
                    "id": 25,
                    "parent_id": 23,
                    "order": 2,
                    "title": "订单日志",
                    "icon": "el-icon-tickets",
                    "uri": "order/log",
                    "permission": "[13]",
                    "created_at": "2020-06-07 21:01:48",
                    "updated_at": "2020-06-23 22:10:30"
                },
                {
                    "id": 26,
                    "parent_id": 16,
                    "order": 2,
                    "title": "活动签到",
                    "icon": "el-icon-toilet-paper",
                    "uri": "activity/enter",
                    "permission": "[15]",
                    "created_at": "2020-06-10 00:53:13",
                    "updated_at": "2020-06-23 22:19:18"
                },
                {
                    "id": 29,
                    "parent_id": 21,
                    "order": 1,
                    "title": "轮播图",
                    "icon": "el-icon-orange",
                    "uri": "slideshow",
                    "permission": "[18]",
                    "created_at": "2020-06-23 22:00:57",
                    "updated_at": "2020-06-23 22:06:53"
                },
                {
                    "id": 30,
                    "parent_id": 0,
                    "order": 3,
                    "title": "客户",
                    "icon": "el-icon-s-custom",
                    "uri": "members",
                    "permission": "[6,8]",
                    "created_at": "2020-06-23 22:14:33",
                    "updated_at": "2020-06-23 22:14:46"
                },
                {
                    "id": 31,
                    "parent_id": 30,
                    "order": 1,
                    "title": "客户管理",
                    "icon": "el-icon-user",
                    "uri": "member",
                    "permission": "[6]",
                    "created_at": "2020-06-23 22:16:28",
                    "updated_at": "2020-06-23 22:16:28"
                },
                {
                    "id": 32,
                    "parent_id": 30,
                    "order": 2,
                    "title": "积分日志",
                    "icon": "el-icon-view",
                    "uri": "member/score/log",
                    "permission": "[8]",
                    "created_at": "2020-06-23 22:17:26",
                    "updated_at": "2020-06-23 22:17:26"
                }
            ]
        }';
    }
}
